require "proto/gm/message/ReqGmCommandMessage"

UIDebug = {}
HelperFunc.SetUIEnv(UIDebug)
local this = UIDebug
this.gameObject = nil
this.transform = nil
this.LuaBehaviour = nil
this.view = nil
this.bg = nil
this.sendBtn = nil
this.contextInput = nil

local init = false;
function UIDebug.Init()
    local name, packageName = getUIName(PanelNames.UIDebug);
    panelMgr:ShowUI(name, packageName, this.OnCreate,Config.useLocalUI);
end

function UIDebug.OnCreate(obj)
    --panelMgr:SetTopParent(obj)
    view = obj;
    --transform = obj.transform;
    --LuaBehaviour = transform:GetComponent('LuaBehaviour');
    if not init then
        --this.DefineCom()
        UpdateBeat:Add(this.Update, self);
        obj.visible = false;
    end
    obj.visible = false;
end

function UIDebug.Update()
    --if Input.GetKey(UnityEngine.KeyCode.LeftAlt) and Input.GetKeyDown(UnityEngine.KeyCode.Return) then
    --    view.visible = not view.visible;
    --    if gameObject.activeSelf then
    --        contextInput.text = Util.GetPlayerPrefs("LuaRun")
    --        contextInput:ActivateInputField()
    --    else
    --        Util.SetPlayerPrefs("LuaRun",contextInput.text)
    --    end
    --end
end

function UIDebug.showSelf()
    --if gameObject ~= nil then
    --    gameObject:SetActive(true);
    --    contextInput.text = Util.GetPlayerPrefs("LuaRun")
    --    contextInput:ActivateInputField()
    --end
end
function UIDebug.DefineCom()
    --bg = view:GetChild("bg")
    --sendBtn = view:GetChild("SendBtn"):GetComponent("ButtonEx")
    --contextInput = transform:Find("InputFr/InputFrame/TextInput"):GetComponent("InputField");
    --
    --LuaBehaviour:AddClick(bg.gameObject,this.OnCloseClick)
    --LuaBehaviour:AddClick(sendBtn.gameObject,this.OnRunClick)
end

function UIDebug.OnRunClick(go)
    --local context = contextInput.text
    --if context == nil or context == "" then print("context null") return end
    --Util.SetPlayerPrefs("LuaRun",contextInput.text)
    --this.OnCloseClick()
    --luaMgr:LuaLoadBuffer(context,"LuaRun")
end

function UIDebug.OnCloseClick(go)
    panelMgr:CloseUI("UIDebug",false);
end

return UIDebug